package Xiaofang.Homework.H4.W1;

public class Lock implements Runnable {
    private boolean flag;

    public Lock(boolean flag) {
        this.flag = flag;
    }

    @Override
    public void run() {
        if(flag){
            while (true){
                synchronized (Mlock.o1){
                    System.out.println(Thread.currentThread().getName()+"1");
                    synchronized (Mlock.o2){
                        System.out.println(Thread.currentThread().getName()+"2");
                    }
                }
            }
        }else {
            synchronized (Mlock.o2){
                System.out.println(Thread.currentThread().getName()+"22");
                synchronized (Mlock.o1){
                    System.out.println(Thread.currentThread().getName()+"11");
                }
            }
        }
    }
}
